/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[DeamonThread.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package thread;

/**
 * 守护线程[后台线程]: 在一个进程中如果只剩下了守护线程, 那么守护线程也会死亡
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class DeamonThread extends Thread {

	public DeamonThread(String name) {
		super(name);
	}

	@Override
	public void run() {
		for (int i = 1; i <= 100; i++) {
			System.out.println("更新包目前下载" + i + "%");
			if (i == 100) {
				System.out.println("更新包下载完毕, 准备安装..");
			}
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) throws InterruptedException {
		DeamonThread thread = new DeamonThread("后台线程");
		thread.setDaemon(true); // 设置线程为守护线程
		thread.isDaemon();// 判断线程是否为守护线程
		thread.start();

		for (int i = 0; i < 10; i++) {
			System.out.println(Thread.currentThread().getName() + " " + i);
			Thread.sleep(200);
		}
	}
}
